

var table = document.getElementsByTagName('table')[0];
var tablecontent = document.getElementById('tablecontent');
var myname = document.getElementById('name');
var name = localStorage.getItem("name");
	myname.innerHTML = name;
  function Rankingmsg(num,headimg,name,guestnum){
  	 var tr = document.createElement('tr');
  	 var str =
			"<td>"+
			"<div id='ranking'>"+num+"</div>"+
			"<div id='headphoto'><img src="+headimg+"></div>"+
			"<div id='name'>"+name+"</div>"+
			"<div id='guestsnumber'>"+guestnum+"位宾客</div>"+
			"<div id='guang'></div>"+
			"</td>";
	tr.innerHTML = str;
	return tr;
  }

	function  Jsondata(){
		$.ajax({
			url:"json/personal.json",
			type:"get",
			dataType:"json",
			async:false,
			success: function(res) {
						jsonData = res; //jq自己返回出来的结果	
						main();
				}
		})
		
	}
	Jsondata();
	
function main(){
//	console.log(jsonData);
	

	for(var i=0;i<jsonData.length;i++){
		var tr = Rankingmsg(null,jsonData[i].head_portrait,jsonData[i].name,jsonData[i].guest_number);
		table.appendChild(tr);
	}
	
	var tr_all = document.getElementsByTagName('tr');
//	console.log(tr_all.length)
	for(var j=0;j<tr_all.length;j++){
		for(var k=j+1;k<tr_all.length;k++){
			if(parseInt(tr_all[j].children[0].children[3].textContent)<parseInt(tr_all[k].children[0].children[3].textContent)){
				table.insertBefore(tr_all[k],tr_all[j]);
			}
		}	
	}
	
	for(var l=0;l<tr_all.length;l++){
			tr_all[l].children[0].children[0].textContent = l+1;
	}
	
//	console.log(name);
	
}
